package ac2.util.serial.packets;

import ac2.Global;
import msg.AC2Messages;

public class TemperatureUpdatePacket extends AC2Packet {
	
	private int _reading;
	private int _count;

	public TemperatureUpdatePacket(byte[] packet) throws Exception
	{
		super(packet);
	}
	
	public TemperatureUpdatePacket(byte targetNode, int reading)
	{
		super(targetNode, AC2Messages.FUNCTION_TEMPERATURE_UPDATE);
	}
	
	public int getReading()
	{
		return _reading;
	}
	
	public int getCount()
	{
		return _count;
	}
	
	@Override
	protected void fillBody(byte[] packet, int start, int length) {
		// TODO Auto-generated method stub

		// NOT DOING ANYTHING WITH THIS...ONLY INCOMING MESSAGES
	}

	@Override
	protected void parseBody() {
		Global.Debug("TemperatureUpdatePacket.parseBody");
         // for right now, our message occupies the last two bytes
         
         // ARGH!!! I hate that java doesn't have unsigned numeric types...
         // I spent 2 hours for this 1 line!
		
         _reading = (256 * (packet[11] & 0xFF)) + (packet[12] & 0XFF);
         _count = packet[13] & 0xFF;
         
         Global.Debug("   ParseBody Object = " + toString());
         Global.Debug("   ParseBody Reading = " + getReading());
         Global.Debug("   ParseBody Count = " + getCount());
	}

}